﻿#ifndef FRIDGEDEVICE_H
#define FRIDGEDEVICE_H

#include <QObject>
#include <QSerialPort>
#include <QMap>
#include <QSerialPortInfo>
#include <QTimer>

#include <QMap>

class FridgeDevice : public QObject
{
    Q_OBJECT
public:
    explicit FridgeDevice(QObject *parent = nullptr);
    virtual ~FridgeDevice();
    static FridgeDevice * gestance();

    void initComSeriel();
    unsigned short count_CRC(unsigned char *addr, int num);


    //获取设备状态
    void getDevice();
    // 获取参数
    void readParam();
    //获取温度
    void readTemp();

    //读取报警信息
    void readCallPolice();


    //关闭设备
    void openSetDevice();
    //打开设备
    void closeSetDevice();
    //设置温度
    void setSetTemperature( short mins ,short maxs);



    //关闭设备
    void openDevice();
    //打开设备
    void closeDevice();
    //设置温度
    void setTemperature( short mins ,short maxs);




    void testData();

    //获取下线设置温度
    short getMinsTemp();
    //获取上线设置温度
    short getMaxsTemp();

    //柜温探头温度
    short getCabinetTemp();
    //蒸发探头温度
    short getVaporTemp();
    //冷凝探头温度
    short getCondenTemp();
    /*
 *
 * 柜温探头故障 0x0000 Bit 0：无报警 1：报警
 * 除霜探头故障 0x0001 Bit 0：无报警 1：报警
 * 冷凝探头故障 0x0002 Bit 0：无报警 1：报警
 * 门打开报警 0x0003 Bit 0：无报警 1：报警
 * 柜温低温报警 0x0004 Bit 0：无报警 1：报警
 * 柜温高温报警 0x0005 Bit 0：无报警 1：报警
 * 冷凝高温报警 0x0006 Bit 0：无报警 1：报警
 * 冷凝保护报警 0x0007 Bit 0：无报警 1：报警
 *
*/
    int getCallPolice(int types);

    int getDeviceStatus();

    void sendDelayCmd();


    bool getFridgeRuns();




signals:

public slots:
    void onDataReceived();
    void onSendDelayCmdTimer();
    void onOpenDelayCmdTimer();
    void onCloseDelayCmdTimer();
    void onSetDelayCmdTimer();


private:
    static FridgeDevice * m_fridgeDevice;
    QSerialPort * m_serial;
    QByteArray m_currentData ;
    unsigned char m_address;
    unsigned char m_cmds;
    short m_minsTemp;
    short m_maxsTemp;

    short m_cabinetTemp;
    short m_vaporTemp;
    short m_condenTemp;
    unsigned char m_deviceStatus;
    QMap<int ,int> m_callPoliceMap;

    QTimer * m_sendDelayCmdTimer;
    int m_sendDelayCmdStatus;

    short m_setmins ;
    short m_setmaxs;

    QTimer * m_openCmdTimer;

    QTimer * m_closeCmdTimer;

    QTimer * m_setTempCmdTimer;
    bool m_isFridgeRuns;

};

#endif // FRIDGEDEVICE_H
